<?php
namespace app\api\controller;
use app\common\controller\BaseApi;

/**
 * 卡管理逻辑处理
 */
class Interfaces extends BaseApi
{
	public function _initialize()
    {
    }
	
	/**
	 * 获取原卡信息
	 **/
	function get_old_interface($card_no,$shop_id){
		 $interface=db("Interface")->fetchsql(FALSE)->where(" card_no='$card_no' and shop_id=$shop_id ")->find();
		 if(empty($interface)){
		 	  $this->ajax_error("","0003","卡号不存在");
		 }else{
		 	 if($interface['is_original']==1){// 原卡
		 	 	 return $interface;
		 	 }else if($interface['owner_type']==5){
		 	 		return $interface;
		 	 }else{//如果是借计卡 则查找 原卡
		 	 	return db("Interface")->find($interface['original_id']);
		 	 }
		 }
	}
	
	/**
	 * 获取店铺列表
	 * http://smartgym.com/api/Interfaces/GetShops
	 * */
	public function GetShops(){
			$time=input("t");
			$sign=input("sign");
			if (($time + 300) < time() || ($time - 300) > time()) {//接口调用时间操过5分钟
                return $this->api_ajax_error("","链接已经过期");
            }
            if ($sign != md5("client_" . $time)) {
                return $this->api_ajax_error("","签名错误！");
            }
			$list=db("Shop")->where("length(shop_code)>5")->column("shop_code,shop_name");
			if(empty($list)){
				return $this->api_ajax_error("","没有更多的数据");
			}
			return $this->api_ajax_success(json_encode($list,JSON_UNESCAPED_UNICODE));
	} 
}
